var setting = {};
//	产品类别树
var productClass = [{
	name: "所有类型",
	open: true,
	iconSkin: "pIconfolder",
	children: [{
			name: "住宅",
			open: true,
			iconSkin: "pIconfolder",
			children: [{
					name: "联排",
					iconSkin: "iconfile",
				},
				{
					name: "高层",
					iconSkin: "iconfile",
				},
			]
		},
		{
			name: "商铺",
			open: false,
			iconSkin: "pIconfolder",
			children: [{
					name: "地下商铺",
					iconSkin: "iconfile",
				},
				{
					name: "底商",
					iconSkin: "iconfile",
				},
				{
					name: "新天地",
					iconSkin: "iconfile",
				},
			]
		},
		{
			name: "车位",
			open: false,
			iconSkin: "pIconfolder",
			children: [{
					name: "有产权车位",
					iconSkin: "iconfile",
				},
			]
		},
		{
			name: "写字楼",
			open: false,
			iconSkin: "pIconfolder",
			children: [{
					name: "办公室SOHO",
					iconSkin: "iconfile",
				},
				{
					name: "甲级写字楼",
					iconSkin: "iconfile",
				},
			]
		}
	]
}];
//组织机构树
var organizClass = [{
	name: "选择",
	open: true,
	iconSkin: "pIconfolder",
	children: [{
			name: "集团总部",
			open: true,
			iconSkin: "pIconfolder",
			children: [{
					name: "业务流程",
					iconSkin: "pIconfolder",
					children: [{
							name: "行政管理",
							iconSkin: "iconfile"
						},
						{
							name: "信息管理",
							iconSkin: "iconfile"
						}
					]
				},
				{
					name: "个人事务",
					iconSkin: "pIconfolder",
					children: [{
						name: "测试",
						iconSkin: "iconfile"
					}]
				},
				{
					name: "请示报告",
					iconSkin: "iconfile"
				}
			]
		},
		{
			name: "地产板块",
			iconSkin: "pIconfolder",
			children: [{
				name: "北京区域",
				iconSkin: "pIconfolder",
				children: [{
						name: "区域流程",
						iconSkin: "iconfile"
					},
					{
						name: "太原地区",
						iconSkin: "iconfile"
					},
					{
						name: "太原地区",
						iconSkin: "iconfile"
					},
					{
						name: "太原地区",
						iconSkin: "iconfile"
					},
					{
						name: "太原地区",
						iconSkin: "iconfile"
					}
				]
			}]
		},
		{
			name: "酒店集团",
			iconSkin: "pIconfolder",
			children: [{
				name: "业务事业部",
				iconSkin: "pIconfolder",
				children: [{
						name: "TEST",
						iconSkin: "iconfile"
					},
					{
						name: "太原地区",
						iconSkin: "iconfile"
					}
				]
			}]
		}
	]
}];

$(function(){
	// 引入头部，左侧
	// $("#headerbox").load("../common/header.html");
	// $("#leftSlider").load("../common/leftSlider.html");
	//	有导航的页面收拉导航功能
	$('.toggle-nav').click(function() {
		$('.left-menu').toggleClass('little');
		$('.rightMain').toggleClass('large');
	});
	//	搜索框下拉功能
	$('.toggle-advance-search').on('click', function() {
		$('.advance-search-content').stop().slideToggle();
		$(this).find('span').toggleClass('caret').toggleClass('caretUp');
	})
	// 页面tab切换
	$('#myTab a').click(function (e) {
		e.preventDefault();
		$(this).tab('show');
		$(this).addClass('active').siblings().removeClass('active');
	})
	//	日历插件
	$(".bs-timepicker").datetimepicker({
		language: 'zh',
		//format: 'yyyy-mm-dd hh:ii',//调用年月日时分 打开
		format: 'yyyy-mm-dd', //调用年月日 打开
		minView: 2, //调用年月日 打开
		//format: 'hh:ii',//调用时分 打开
		//startView:1,//调用时分 打开
		todayBtn: true,
		clearBtn: true,
		autoclose: true
	});
	//	向上弹出的日历插件
    $(".bs-timepicker-up").datetimepicker({
        language: 'zh',
        //format: 'yyyy-mm-dd hh:ii',//调用年月日时分 打开
        format: 'yyyy-mm-dd', //调用年月日 打开
        pickerPosition:'top-right',
        minView: 2, //调用年月日 打开
        //format: 'hh:ii',//调用时分 打开
        //startView:1,//调用时分 打开
        todayBtn: true,
        clearBtn: true,
        autoclose: true
    });
	//	资产类别树引用
	$.fn.zTree.init($("#productType"), setting, productClass);

	//  列表点击排序
	$('.sortPX').on('click', function() {
		var arrtr = [];
		var _this = $(this);
		var _index = _this.parent().index('th');
		var tbody = _this.parents('thead').eq(0).siblings('tbody');
		var trs = tbody.children('tr');
		arrtr = trs;
		if(!_this.hasClass('has')){
			_this.addClass('has').parent().siblings().find('.has').removeClass('has');
		}
		if(_this.hasClass('up')) {
			_this.removeClass('up');
			arrtr.sort(function(a, b) {
				var aa = $(a).find('td').eq(_index).text().replace(/\,|\-/g, '');
				var bb = $(b).find('td').eq(_index).text().replace(/\,|\-/g, '');
				var ab = parseFloat(aa);
				if(ab == aa) {
					return aa - bb;
				}
				var a = $(a).find('td').eq(_index).text().charCodeAt();
				var b = $(b).find('td').eq(_index).text().charCodeAt();
				return a - b;
			});
		} else {
			_this.addClass('up');
			arrtr.sort(function(a, b) {
				var aa = $(a).find('td').eq(_index).text().replace(/\,|\-/g, '');
				var bb = $(b).find('td').eq(_index).text().replace(/\,|\-/g, '');
				var ab = parseFloat(aa);
				if(ab == aa) {
					return bb - aa;
				}
				var a = $(a).find('td').eq(_index).text().charCodeAt();
				var b = $(b).find('td').eq(_index).text().charCodeAt();
				return b - a;
			});
		}
		tbody.html(arrtr);
	});
	
});


